package sjtu.ist.warehouse4ws.service;

import java.util.ArrayList;
import java.util.List;

import sjtu.ist.warehouse4ws.dao.CompanyDaoHibernate;
import sjtu.ist.warehouse4ws.dao.GroupCompanyDaoHibernate;
import sjtu.ist.warehouse4ws.dao.ModelgroupDaoHibernate;
import sjtu.ist.warehouse4ws.model.Company;
import sjtu.ist.warehouse4ws.model.GroupCompany;
import sjtu.ist.warehouse4ws.model.Modelgroup;
import sjtu.ist.warehouse4ws.vo.FullGroupCompanyVO;


public class GroupCompanyServiceImpl implements GroupCompanyService{
	
	private GroupCompanyDaoHibernate groupCompanyDao;
	private CompanyDaoHibernate companyDao;
	private ModelgroupDaoHibernate modelgroupDao;
	
	public void setGroupCompanyDao(GroupCompanyDaoHibernate groupCompanyDao){
		this.groupCompanyDao = groupCompanyDao;
	}
	
	

	@Override
	public void save(GroupCompany groupCompany) {
		groupCompanyDao.save(groupCompany);
	}

	@Override
	public void update(GroupCompany groupCompany) {
		groupCompanyDao.update(groupCompany);
	}

	@Override
	public void delete(Integer id) {
		groupCompanyDao.delete(id);
	}

	@Override
	public void delete(GroupCompany groupCompany) {
		groupCompanyDao.delete(groupCompany);
	}

	@Override
	public List<GroupCompany> findByName(String name) {
		return groupCompanyDao.findByName(name);
	}

	@Override
	public List<GroupCompany> findByCompany(String companyName) {
		return groupCompanyDao.findByCompany(companyName);
	}



	@Override
	public GroupCompany get(Integer id) {
		// TODO Auto-generated method stub
		return groupCompanyDao.get(id);
	}



	@Override
	public List<GroupCompany> getGroupCompanyList() {
		// TODO Auto-generated method stub
		return (List<GroupCompany>) groupCompanyDao.findAllGroupCompany();
		
	}
	
	//获得vo
	public FullGroupCompanyVO getFullGroupCompany(GroupCompany groupCompany){
		Modelgroup modelgroup=modelgroupDao.get(groupCompany.getGroupId());
		Company company=companyDao.get(groupCompany.getCompanyId());
		FullGroupCompanyVO fgcvo=new FullGroupCompanyVO();
		fgcvo.setId(groupCompany.getId());
		fgcvo.setGroupId(groupCompany.getGroupId());
		fgcvo.setGroupName(modelgroup.getGroupName());
		fgcvo.setCompanyId(groupCompany.getCompanyId());
		fgcvo.setCompanyName(company.getName());
		fgcvo.setStatus(groupCompany.getStatus());
		fgcvo.setGroupDescription(modelgroup.getDescription());
		return fgcvo;
	}



	public void setCompanyDao(CompanyDaoHibernate companyDao) {
		this.companyDao = companyDao;
	}



	public void setModelgroupDao(ModelgroupDaoHibernate modelgroupDao) {
		this.modelgroupDao = modelgroupDao;
	}
	


}
